package com.tzyh.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author hxd
 * @Date 2022/1/18 16:53
 * @Description
 **/
@RestController
@Slf4j
public class TestController {
    @Bean
    @LoadBalanced
    public RestTemplate rest() {
        return new RestTemplate();
    }
    @Autowired
    RestTemplate restTemplate;

    @GetMapping(value = "/gotoUser")
    @ResponseBody
    public Map<String,Object> getUser(@RequestParam Integer id){
        log.info("==========gotoUser======id={}",id);
        Map<String,Object> data = new HashMap<>();
        data = restTemplate.getForObject("http://cloudpivot-web-api/api/public/getUser?id="+id,Map.class);
        log.info("================data={}",data);
        return data;
    }
}
